//获取应用实例
var app = getApp();
var util = require('../../utils/util.js');
var WxAutoImage = require('../../WxAutoImage/WxAutoImage.js');
Page({
  data: {
    "is_over": false,
    "no_data": false,
    details:[]
  },
  onLoad: function (options) {
    this.getConfig();
    var that = this;
    that.setData({
      id: options.id
    })

    var id = that.data.id;
    // console.log(that.data.id);
    var offset = (this.page - 1) * this.size;
    var size = this.size;
    var data = {
      "offset": offset,
      "size": size
    };
    var url = this.baseApiUrl + "details";
    var self = this;

    util.ajax({
      "url": url+"?id="+id,
      "data": data,
      "success": function (data) {

        self.setData({
          'details': data[0]
        });
        console.log('获得接口成功', data);
      }
    });

  },
  map:function(){
    wx.showModal({
      title: '腾讯地图',
      content: '是否前往该地段',
      confirmText: "确定",
      cancelText: "取消",
      success: function (res) {
        console.log(res);
        if (res.confirm) {
          wx.navigateTo({
            url: '../map/map',
            success: function () { 
              console.log('1')
            },
            fail:function(){
              console.log(2);
            }
          })
        } else {
          console.log('取消')
        }
      }
    });
  },
  
  loadMore: function (res) {
    // wx.showNavigationBarLoading()
    console.log('到底了');

    if (this.data.review == 0) {
      return
    } else {
      //加载更多
      //concat()方法，他将2个或2个以上的数组连接起来
      wx.showToast({
        title: '加载中...',
        icon: 'loading',
        duration: 2000
      })

      //前 x=5+5=10 ,后10
      //前x=10+10=20 后20
      //前x=20+20=40 后40

      var that = this;
      that.data.review[curid] = that.data.navSectionItems[curid].concat(that.data.navSectionItems[curid]);
      that.setData({
        list: that.data.navSectionItems
      })
    }
  },

  //配置方法
  getConfig: function () {
    this.baseApiUrl = util.config('baseApiUrl');
    this.size = util.config('page_size');
    this.offset = util.config('page_offset');
    this.page = 1;
  },

  pullDown: function (e) {
    this.page = this.page + 1;
    this.goodsList();
  },
  onReady: function () {
    //wx.hideNavigationBarLoading();
    // 页面渲染完成
  },
  onShow: function () {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      }
    })
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  //监听用户下拉动作
  onPullDownRefresh: function () {
    this.refresh();
    this.review();
    // this.bannerList();

  },
  error: function (data) {
    if (data.url == undefined) {
      data.url = '../index/index';
    }
    if (data['result'] == 'fail') {
      this.setData({
        error: data
      });
    } else {
      //console.log('接口获取数据错误！！！');
    }
    this.setData({ loaded: true });
  },
  //跳转支付页面
  pay:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 1000,
      mask: true,
      success:function(){
        setTimeout(function () {
          wx.navigateTo({
            url: '../pay/pay',
          })
        }, 1000)
      }	
    });
   
  },
  review: function () {
    var offset = (this.page - 1) * this.size;
    var size = this.size;
    var data = {
      "offset": offset,
      "size": size
    };
    var url = this.baseApiUrl + "review";
    var self = this;

    util.ajax({
      "url": url,
      "data": data,
      "success": function (data) {

        self.setData({
          'review': data
        });
        console.log('获得接口成功', data);
      }
    });
  },
  cusImageLoad: function (e) {
    var id = e.currentTarget.dataset.id;
    var that = this;
    var data = {};
    data[id] = WxAutoImage.wxAutoImageCal(e);
    that.setData(data);
  },
  cusImageGoods: function (e) {
    var that = this;
    that.setData(util.imageUtil(e));
  },

  // loadding: function () {
  //   this.setData({ loaded: false });
  // },
  // loaded: function () {
  //   this.setData({ loaded: true });
  // },




})
